<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>背景颜色切换</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
            transition: background-color 0.5s ease;
        }
        #control-panel {
            margin-top: 20px;
        }
        #control-panel button {
            padding: 10px 20px;
            font-size: 16px;
            margin: 5px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <h1>点击按钮切换背景颜色</h1>
    <div id="control-panel">
        <button id="red">红色</button>
        <button id="blue">蓝色</button>
        <button id="green">绿色</button>
        <button id="yellow">黄色</button>
        <button id="purple">紫色</button>
    </div>

    <script>
        const body = document.body;

        document.getElementById('red').addEventListener('click', () => {
            body.style.backgroundColor = 'red';
        });

        document.getElementById('blue').addEventListener('click', () => {
            body.style.backgroundColor = 'blue';
        });

        document.getElementById('green').addEventListener('click', () => {
            body.style.backgroundColor = 'green';
        });

        document.getElementById('yellow').addEventListener('click', () => {
            body.style.backgroundColor = 'yellow';
        });

        document.getElementById('purple').addEventListener('click', () => {
            body.style.backgroundColor = 'purple';
        });
    </script>
</body>
</html>